package com.gitee.wsl.io

import kotlinx.io.files.FileMetadata
import kotlinx.io.files.FileSystem
import kotlinx.io.files.Path
import kotlinx.io.files.SystemFileSystem

interface FileManager {

    suspend fun getFileAsString(filename: String): String

    suspend fun saveStringValueToFile(filename: String, value: String)

    suspend fun deleteFile(filename: String)

}

sealed interface PathAble {

    val path:Path

    val fileSystem: FileSystem

    val size:Long get() = fileSystem.metadataOrNull(path)?.size?:-1

    val isExits:Boolean get() = path.exists()

    val isAbsolute: Boolean get() = path.isAbsolute

    val metadata:FileMetadata? get() = fileSystem.metadataOrNull(path)

    val parent: Dir? get() = path.parent?.let { Dir(it) }

    val name: String get() = path.name

    fun exists():Boolean = path.exists()

    fun moveTo(destDir:Dir) = fileSystem.atomicMove(path,destDir.path)

    fun copyTo(destDir:Dir)

    fun delete() = path.delete()

    fun createIfNoExists():Boolean

}


